package top.wu2020.lazy.ws.chat.infrastructure.persistence;

import top.wu2020.lazy.ws.chat.infrastructure.entity.CommunityCommentDO;
import top.wu2020.lazy.ws.chat.infrastructure.converter.CommunityCommentConverter;
import top.wu2020.lazy.ws.chat.infrastructure.mapper.CommunityCommentMapper;
import top.wu2020.lazy.ws.chat.domain.model.community.comment.CommunityCommentRepository;
import org.springframework.stereotype.Repository;
import java.util.stream.Collectors;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import jakarta.annotation.Resource;
import top.wu2020.lazy.ws.chat.domain.model.community.comment.CommunityComment;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
/**
 * describe community_comment 
 *
 * @author Jia wei Wu
 * @date 2024/05/24 08:52 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence 
 **/
@Repository
public class CommunityCommentRepositoryImpl  implements  CommunityCommentRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增
     *
     * @param communityComment 新增     
     * @return {@link Result<CommunityComment>} 新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<CommunityComment> story(CommunityComment communityComment) {
        CommunityCommentDO communityCommentDO = CommunityCommentConverter.INSTANCE.fromCommunityComment(communityComment);
        lazyLambdaStream.upsert(communityCommentDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增
     *
     * @param communityCommentList 批量新增     
     * @return {@link Result<List<CommunityComment>>} 新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<List<CommunityComment>> batchStory(List<CommunityComment> communityCommentList) {
        List<CommunityCommentDO> communityCommentDOList = communityCommentList.stream().map(CommunityCommentConverter.INSTANCE::fromCommunityComment).collect(Collectors.toList());
        lazyLambdaStream.upsert(communityCommentDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个
     *
     * @param communityComment 查询单个     
     * @return {@link Result<CommunityComment>} 领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<CommunityComment> findOne(CommunityComment communityComment) {
        CommunityCommentDO communityCommentDO = CommunityCommentConverter.INSTANCE.fromCommunityComment(communityComment);
        CommunityComment communityCommentOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(communityCommentDO), CommunityComment.class);
        return ResultFactory.successOf(communityCommentOne);
    }

    /**
     * describe 查询多个
     *
     * @param communityComment 查询多个     
     * @return {@link Result<List<CommunityComment>>} 领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<List<CommunityComment>> findList(CommunityComment communityComment) {
        CommunityCommentDO communityCommentDO = CommunityCommentConverter.INSTANCE.fromCommunityComment(communityComment);
        List<CommunityComment> communityCommentList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(communityCommentDO), CommunityComment.class);
        return ResultFactory.successOf(communityCommentList);
    }

    /**
     * describe 分页查询多个
     *
     * @param size 当前页数
     * @param current 当前页
     * @param communityComment 分页查询多个     
     * @return {@link Result<LazyPage<CommunityComment>>} 分页领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<LazyPage<CommunityComment>> findPage(int size,int current,CommunityComment communityComment) {
        CommunityCommentDO communityCommentDO = CommunityCommentConverter.INSTANCE.fromCommunityComment(communityComment);
        LazyPage<CommunityComment> lazyPage = new LazyPage<>(current,size);
        LazyPage<CommunityComment> communityCommentLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(communityCommentDO),lazyPage, CommunityComment.class);
        return ResultFactory.successOf(communityCommentLazyPage);
    }

    /**
     * describe 删除
     *
     * @param communityComment 删除     
     * @return {@link Result<CommunityComment>}      
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<CommunityComment> remove(CommunityComment communityComment) {
        CommunityCommentDO communityCommentDO = CommunityCommentConverter.INSTANCE.fromCommunityComment(communityComment);
        //  lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(communityCommentDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在
     *
     * @param communityComment 领域对象     
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<Boolean> exists(CommunityComment communityComment) {
        CommunityCommentDO communityCommentDO = CommunityCommentConverter.INSTANCE.fromCommunityComment(communityComment);
        Boolean exists=lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(communityCommentDO));
        return ResultFactory.successOf(exists);
    }

}